source("~/Projects/NBI/R/convert2016.R")
nbi <- convert2016("~/Data/2016hwybronlyonefile.zip")
## Warning in convert2016("~/Data/2016hwybronlyonefile.zip"): NAs introduced
## by coercion
## Warning in convert2016("~/Data/2016hwybronlyonefile.zip"): NAs introduced
## by coercion
## Warning in convert2016("~/Data/2016hwybronlyonefile.zip"): NAs introduced
## by coercion
ne <- subset(nbi, stateCode == "NE")
library(MazamaSpatialUtils)
## Loading required package: sp
## Warning: package 'sp' was built under R version 3.4.1
setSpatialDataDir("~/Data/Spatial")
MazamaSpatialUtils::convertUSCensusCounties()
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/helen/Data/Spatial/counties", layer: "cb_2013_us_county_20m"
## with 3221 features
## It has 9 fields
## Integer64 fields read as strings: ALAND AWATER
loadSpatialData("USCensusCounties")
library(maps)
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.4.1
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
neCounties <- subset(USCensusCounties, stateCode == "NE")
ne$county <- getUSCounty(ne$longitude, ne$latitude, dataset = "USCensusCounties", stateCode = "NE")
Nebraska is an interesting case for a couple of reasons. Bridges are not equally distributed throughout the country. There are a lot more bridges in the Eastern half. Fewer in the mountainous, less-developed west. Nebraska lies right in the middle of this divide, with a stark difference in the density of bridges in the eastern and western half of the state.
map("state")
map("state", "neb", col = "red", add = TRUE, lwd = 3)
points(nbi$longitude, nbi$latitude, pch = 17, cex = .05)
map.cities(x = us.cities, minpop = 200000, col = "red", cex = 1.5)
title("Bridges in the Continental US")
Nebraska is also an interesting case when it comes to the age of bridges in the state. In most states, the peak of bridge building was in the 60’s or near that time. In contrast, Nebraska and Oklahoma built the most brides in the 30’s. For these reasons, we will be taking a closer look at bridges in Nebraska to explore their geography and history.
loadSpatialData("NaturalEarthAdm1")
us <- subset(NaturalEarthAdm1, countryCode == "US")
conusID <- us$stateCode
conusID <- setdiff(conusID, c("AK", "HI"))
conus <- subset(us, stateCode %in% conusID)
getmode <- function(v) {
uniqv <- unique(v)
uniqv[which.max(tabulate(match(v, uniqv)))]
}
decadeBreaks <- c(-Inf, seq(1800, 2020, by = 10))
decadeBuilt <- .bincode(nbi$yearBuilt, breaks = decadeBreaks)
decadeBuilt <- c("<1800", as.character(seq(1800,2020,by = 10)))[decadeBuilt]
modeDecadeByState <- aggregate(decadeBuilt ~ nbi$stateCode , FUN = getmode)
modeDecadeByState$decadeBuilt <- as.numeric(modeDecadeByState$decadeBuilt)
modeAgeIndex <- .bincode(2000-modeDecadeByState$decadeBuilt, breaks = seq(9,79, by = 10))
names(modeAgeIndex) <- modeDecadeByState$`nbi$stateCode`
decadeColors <- RColorBrewer::brewer.pal(7, "PuRd")
plot(conus, col = decadeColors[modeAgeIndex[conus$stateCode]])
plot(subset(conus, stateCode == "NE"), lwd = 5, add = TRUE)
legend("bottomleft", c("1930s", "1940s", "1950s", "1960s", "1970s", "1980s", "1990s"), pch = 15, col = decadeColors[7:1])
library(maps)
map("state", "neb")
with(dplyr::filter(nbi, water == 1 & stateCode == "NE"), points(longitude, latitude, pch = 2, cex = .1, col = "blue"))
with(dplyr::filter(nbi, water == 0 & stateCode == "NE"), points(longitude, latitude, pch = 2, cex = .3, col = "red"))
title("All bridges in Nebraska")
legend("bottomleft", c("Bridges over water", "Bridges not over water"),
pch = 17, col = c("blue", "red"), title = "Legend")
We see two very different types of geography when we look at bridges that span water versus bridges that do not span water, like overpasses. Bridges that do not span water will generally only be on large roads and highways where an overpass or underpass is needed. Thus, these bridges directly follow the interstate.
On the other hand, bridges that do span water follow Nebraska’s physical geography. In the western half of the state, the interstate generally follows the Platte river, but when it diverges in the east, we can easily follow the shape of the Platte as it curves up towards Omaha. Tributataries flow in from the north. In the southern part of the state, bridges outline the shape of the Republican river and its tributaries.
knitr::include_graphics("./localImages/Nebraska_ref_2001.jpg")
Why are there so many more bridges in the Eastern half of the state? Western Nebraska is home to the Sandhills, arid and scantily populated. There are bridges where water and roads intersect and Eastern Nebraska is richer in both. However, many parts of Eastern Nebraska are relatively sparsely-populated farmland. Why, then, are there so many bridges? Let’s zoom in a bit.
map("state", "neb", xlim = c(-97.5,-97), ylim = c(42, 42.5))
with(dplyr::filter(nbi, water == 1 & stateCode == "NE"), points(longitude, latitude, pch = 2, cex = .2))
with(dplyr::filter(nbi, water == 0 & stateCode == "NE"), points(longitude, latitude, pch = 2, cex = .5, col = "red"))
leaflet::leaflet() %>%
leaflet::addTiles(urlTemplate="http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}") %>%
# leaflet::addTiles()%>%
leaflet::fitBounds(-97.3681, 42, -97.2302, 42.1631)
We are looking at a corner of Northeastern Nebraska. Now that we can make out individual bridges, we can see that they seem to be relatively evenly-spaced, following what must be rivers. If we take a look at a sattelite image of this same area, we see that, indeed, there are evenly spaced roads outlining the squares of each individual farming plot, which form nice regularly-spaced bridges where they intersect with rivers.
hist(ne$yearBuilt, xlab = "Year Built", main = "Year Built", n = 100)
When were Nebraska’s bridges built? It appears that close to half of them were built in one year in the 1930s. We will examine that phenomenon more in a minute. Ignoring that one outlier year, most bridges were built in the last 50 years or so. Previous to that, there are peaks every 5 to 10 years, which is most likely due to rounding in estimates of each bridge’s founding year. Bridge building seems to start taking off around 1930, perhaps as part of depression-relief projects. There is the huge outlier of 1935, and then in the 40’s, we see a dip again during the war. Besides 1935, most bridges were built in the last 50 years or so, with a peak in the early 60’s, after the signing of the Federal Highway Act spurred road building, with a decline in bridge building since around 1990.
Let’s watch it happen.
yearlyBridgePlot <- function(df, year){
layout(matrix(c(1,2), 2, 1), heights = c(7,3))
par(mar = c(2,2,2,2))
maps::map("state", "neb")
with(subset(df, yearBuilt <= year - 10),
points(longitude, latitude, cex = .3, pch = 17, col = "grey"))
for(i in 1:9){
with(subset(df, yearBuilt == year - i),
points(longitude, latitude, cex = .4, pch = 17,
col = adjustcolor("grey", red.f = 2-i/10, green.f = i/10, blue.f = i/10)))
}
with(subset(df, yearBuilt == year), points(longitude, latitude, pch = 24, cex = 1, bg = "red", col = "black"))
title(as.character(year))
par(mar = c(1,4,5,4), mgp = c(2,.5,0), yaxs = "i")
plot(NA, xlim = c(1885, 2015), ylim = c(0,10), axes = F, ann = F)
axis(3, at = seq(1885, 2015, by = 10))
points(year, 8.8, pch = 17, cex = 2)
title("Year")
}
animation::saveHTML(for(i in min(ne$yearBuilt):max(ne$yearBuilt)){
yearlyBridgePlot(df = ne, year = i)
},
interval = .2, htmlfile = "nebraska_animation.html", autobrowse = FALSE)
## HTML file created at: nebraska_animation.html
htmltools::includeHTML("./nebraska_animation.html")
## Animations generated in R version 3.4.0 (2017-04-21)
## using the package animation
library(bindrcpp)
library(dplyr)
library(maps)
library(MazamaSpatialUtils)
library(sp)
for (i in min(ne$yearBuilt):max(ne$yearBuilt)) {
yearlyBridgePlot(df = ne, year = i)
}
## R version 3.4.0 (2017-04-21)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Other packages: bindrcpp 0.2, dplyr 0.7.1, maps 3.2.0,
## MazamaSpatialUtils 0.5.0, sp 1.2-5All this makes sense with our understanding of US history. So what happened in Nebraska in 1935?
knitr::include_graphics(c("./localImages/webberrailcars2.jpg","./localImages/Escape from McCook Power and Light.jpg"))
In June of 1935 a massive flood overflowed the banks of the Republican River, killing nearly 100 Nebraskan people and 46,500 Nebraskan chickens. It wiped out 341 miles of Nebraskan highways and 57,000 acres of farmland. It was a massive flood. As one may expect, many bridges were washed out. Here are some examples.
knitr::include_graphics(c("./localImages/bridge1.jpg","./localImages/WebberBridgeB.jpg"))
With so many bridges destroyed, we would expect that just as many bridges had to be rebuilt. Thus, is the huge spike in bridge building in 1935 a sign of enthusiastic expansion of road networks, or an indication of the aftermath of a natural disaster which destroyed many bridges? Let’s take a closer look at the bridges built in 1935.
floodBridges <- subset(ne, yearBuilt == 1935)
According to our dataset, 2714 were built in 1935. That’s a lot. 307 highway bridges were reportedly destroyed in the flood, and, we expect, rebuilt shortly thereafter. This does not account for railroad bridges or bridges on small county roads, so it is fair to expect the total number of reconstructed bridges to be significantly higher than 307. Is it plausible that the vast majority of bridges built in 1935 were non-highway bridges destroyed in the flood? They do seem to be primarily non-highway bridges. The average daily traffic for bridges built in 1935 is 160.8655122 vehicles whereas the average daily traffic for all Nebraskan bridges is 1471.3989827 vehicles. The vast majority of the bridges built in 1935 carry 100 cars or fewer. In fact, only 11% of the bridges built in 1935 carry over 100 cars per day, on average, which indicates that they are generally small, non-highway bridges, the kind that would easily get washed out in a flood. Now, let’s take a look at where these bridges actually are.
maps::map("state", "nebraska")
points(floodBridges$longitude, floodBridges$latitude, pch = 17, cex = .5)
title("Bridges built in 1935")
The Republican River winds through Southern Nebraska. Many of the 1935 bridges were, indeed, built near the Republican River. However, just as many, if not more, were built in other parts of Nebraska. Perhaps the weather event which flooded the Republican River flooded other rivers too, just with less drastic cost to life and property and less thorough media coverage.
hist(floodBridges$averageCarCount, n = 100000, main = "Traffic on Bridges Built in 1935", xlab = "Average Daily Traffic")
hist(floodBridges$averageCarCount, n = 100000, xlim = c(0,500), main = "Zoomed-in Histogram of Traffic on Bridges Built in 1935", xlab = "Average Daily Traffic")
breaks <- c(0,seq(16,136, by = 20))
neColors <- RColorBrewer::brewer.pal(7, "PuRd")
colorIndex <- .bincode(ne$age, breaks = breaks)
ne$colorIndex <- colorIndex
map("state", "neb")
points(ne$longitude, ne$latitude, cex = .3, pch = 17, col = neColors[colorIndex])
legend("bottomleft", c("1880-1900", "1900-1920", "1920-1940", "1940-1960", "1960-1980", "1980-2000", "2000-2017"), pch = 17, col = neColors[7:1])
map("state", "neb")
points(ne$longitude, ne$latitude, pch = 2, cex = ne$averageCarCount/20000)
legend("bottomleft", c("1,000", "10,000", "100,000", "200,000"), pch = 2, pt.cex = c(1000/20000, 10000/20000, 100000/20000, 200000/20000), title = "Daily motor Traffic", y.intersp = 4, ncol = 2)
title("Traffic on Nebraska's Bridges")
As expected, traffic is heaviest along the highways. There are particular high-traffic clumps at Omaha and Lincoln. Most bridges have low traffic. Less than about 1,000 vehicles per day and they barely show up on the map.
meanAgeByCounty <- aggregate(data=ne, age~county, FUN = mean)
breaks <- c(24.4, seq(30,55, by = 5), 60.2)
colorIndex <- .bincode(meanAgeByCounty$age, breaks = breaks)
names(colorIndex) <- meanAgeByCounty$county
plot(neCounties, col = neColors[colorIndex[neCounties$countyName]])
legend("bottomleft", c("25-30", "30-35", "35-40", "40-45", "45-50","50-55", "55-60"), pch = 15, col = neColors)
getmode <- function(v) {
uniqv <- unique(v)
uniqv[which.max(tabulate(match(v, uniqv)))]
}
modeYearByCounty <- aggregate(data = ne, yearBuilt~county, FUN = getmode)
hist(modeYearByCounty$yearBuilt)
breaks <- c(seq(1929, 1999, by = 10), 2017)
modeIndex <- .bincode(modeYearByCounty$yearBuilt, breaks = breaks)
modeColors <- RColorBrewer::brewer.pal(8, "PuRd")
names(modeIndex) <- modeYearByCounty$county
plot(neCounties, col = modeColors[8:1][modeIndex[neCounties$countyName]])
legend("bottomleft", c("1930s", "1940s", "1950s", "1960s", "1970s", "1980s", "1990s", "2000s"), pch = 15, col = modeColors[8:1])